//
//  ViewController.m
//  CustomProgressTest
//
//  Created by 美鑫科技 on 16/5/4.
//  Copyright © 2016年 MorpLCP. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *contentView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UIView *vieww = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.size.width / 2.0 - 150, 10, 100, 5)];
    vieww.backgroundColor = [UIColor redColor];
    vieww.tag = 10050;
    [self.contentView addSubview:vieww];
    [self addNewLayer];
}
- (IBAction)action2Go:(UIButton *)sender {
    UIView *viewwwww = [self.contentView viewWithTag:10050];
    static int i = 0;
    if (i == 0) {
        [UIView transitionWithView:viewwwww duration:2 options:(UIViewAnimationOptionTransitionNone) animations:^{
            CGRect newFrame =  viewwwww.frame;
            newFrame.origin.x = newFrame.origin.x + 100;
            viewwwww.frame = newFrame;
        } completion:nil];
        i = 1;
    } else{
        [UIView transitionWithView:viewwwww duration:2 options:(UIViewAnimationOptionTransitionNone) animations:^{
            CGRect newFrame =  viewwwww.frame;
            newFrame.origin.x = newFrame.origin.x - 100;
            viewwwww.frame = newFrame;
        } completion:nil];
        i = 0;
    }
}

- (void)addNewLayer{
    UIBezierPath *path = [UIBezierPath bezierPath];
    CGPoint point1 = CGPointMake(CGRectGetMidX(self.view.frame) - 50, 10);
    CGPoint point2 = CGPointMake(CGRectGetMidX(self.view.frame) + 50, 10);
    CGPoint point3 = CGPointMake(CGRectGetMidX(self.view.frame) + 50, 15);
    CGPoint point4 = CGPointMake(CGRectGetMidX(self.view.frame) - 50, 15);
    [path moveToPoint:point1];
    [path addLineToPoint:point2];
    [path addLineToPoint:point3];
    [path addLineToPoint:point4];
    [path closePath];
    CAShapeLayer *layer = [CAShapeLayer layer];
    layer.path = [path CGPath];
    self.contentView.layer.mask = layer;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
